#include "stdafx.h"
#include "TextFile.h"



CTextFile::CTextFile()
{
}


CTextFile::~CTextFile()
{
}

uint CTextFile::OpenToRead( char filename[1024])
{
    return fopen_s( &fp, filename, "r" );
}

uint CTextFile::OpenToBinaryRead( char filename[1024])
{
    return fopen_s( &fp, filename, "rb" );
    rewind(fp);
}

uint CTextFile::OpenToReWrite( char filename[1024])
{
    return fopen_s( &fp, filename, "w" );
}

uint CTextFile::OpenToBinaryReWrite( char filename[1024])
{
    return fopen_s( &fp, filename, "wb" );
}

uint CTextFile::Close( )
{
    return fclose(fp);
}

char * CTextFile::ReadTextLine( char textline[65536] )
{
    return fgets (textline , 65535 , fp);
}

size_t CTextFile::WriteBytes( void *ptr, uint count )
{
    return fwrite (ptr , 1, count, fp);
}

size_t CTextFile::ReadBytes( void *ptr, uint count )
{
    return fread (ptr , 1, count, fp);
}


uint CTextFile::EndOfFile()
{
    return feof( fp );
}

size_t CTextFile::Test()
{
    rewind(fp);
    unsigned char c = 255;
    while( !EndOfFile() ){
        ReadBytes( &c, 1 );
        cout << "byte = "<<(unsigned)c<<endl;
    }
    
    cout << "Done"<<endl;
    return 0;
}